﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SD.IDAL;
using SD.Entities;
using System.Data;
using System.Data.SqlClient;

namespace SD.DAL
{
    public class ReferenceDataDAO : BaseDAO, IReferenceDataDAO
    {
        #region IReferenceDataDAO Members

        public List<ReferenceData> GetAll()
        {
            SqlCommand comm = CreateCommand();
            comm.CommandText = "GetAllRef";

            DataTable dt = ExecuteSelectCommand(comm);

            List<ReferenceData> list = new List<ReferenceData>();
            foreach (DataRow row in dt.Rows)
            {
                ReferenceData a = new ReferenceData();
                a.RefId = row["RefID"].ToString();
                a.RefValue = row["RefValue"].ToString();
                a.RefCode = row["RefCode"].ToString();
                list.Add(a);
            }

            return list;
        }
        public List<ReferenceData> GetByRefCode(string refCode)
        {
            SqlCommand comm = CreateCommand();
            comm.CommandText = "RefDataGetByRefCode";
            comm.Parameters.AddWithValue("@RefCode", refCode);
            DataTable dt = ExecuteSelectCommand(comm);

            List<ReferenceData> list = new List<ReferenceData>();
            ReferenceData r = null;

            foreach (DataRow row in dt.Rows)
            {
                r = new ReferenceData();
                r.RefId = row["RefID"].ToString();
                r.RefCode = row["RefCode"].ToString();
                r.RefValue = row["RefValue"].ToString();
                list.Add(r);
            }

            return list;
        }
        public List<ReferenceData> GetDetails2(string orgId)
        {
            return null;
        }
        public List<ReferenceData> GetRefByCodition(string bussinessname, string siccode)
        {
            SqlCommand comm = CreateCommand();
            comm.CommandText = "GetRefDataByCodition";
            comm.Parameters.AddWithValue("@RefValue", bussinessname);
            comm.Parameters.AddWithValue("@RefCode", siccode);
            DataTable dt = ExecuteSelectCommand(comm);

            List<ReferenceData> list = new List<ReferenceData>();
            foreach (DataRow row in dt.Rows)
            {
                ReferenceData a = new ReferenceData();
                a.RefId = row["RefID"].ToString();
                a.RefValue = row["RefValue"].ToString();
                a.RefCode = row["RefCode"].ToString();
                list.Add(a);
            }

            return list;
        }

        public ReferenceData GetById(string refId)
        {
            SqlCommand comm = CreateCommand();
            comm.CommandText = "RefDataGetById";
            comm.Parameters.AddWithValue("@RefID", refId);
            DataTable dt = ExecuteSelectCommand(comm);

            ReferenceData r = null;
            if (dt.Rows.Count > 0)
            {
                DataRow row = dt.Rows[0];
                r = new ReferenceData();
                r.RefId = row["RefID"].ToString();
                r.RefCode = row["RefCode"].ToString();
                r.RefValue = row["RefValue"].ToString();
            }

            return r;
        }

        public bool Insert(ReferenceData refData)
        {
            throw new NotImplementedException();
        }

        public bool Update(ReferenceData refData)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string refId)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
